package com.tjetc.myservlet;

import java.io.OutputStream;

/**
 * @author gaoyongxiang
 * @version v1.0
 * @date 2025/9/1
 */
public class CalculateServlet extends MyHttpServlet {

    @Override
    protected void doPost(MyHttpRequest request, MyHttpResponse response) {
        try {
            int num1 = Integer.parseInt(request.getParameter("num1"));
            int num2 = Integer.parseInt(request.getParameter("num2"));

            int result = num1 + num2;

            // 处理响应
            String respMsg = MyHttpResponse.respHeader + result;

            OutputStream outputStream = response.getOutputStream();
            outputStream.write(respMsg.getBytes());
//            outputStream.flush();
            outputStream.close();
        } catch (Exception e) {

        }

    }

    @Override
    protected void doGet(MyHttpRequest request, MyHttpResponse response) {
        doPost(request, response);
    }


    @Override
    public void init() throws Exception {

    }

    @Override
    public void destroy() {

    }
}